package com.dp.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import com.dp.service.impl3.ClientCommentsServiceImpl3;
import com.dp.vo.ClientComments;

public class ClientCommentsServlet extends HttpServlet {
	
	private static Logger logger = Logger.getLogger(ClientCommentsServlet.class);
	private ClientCommentsServiceImpl3 clientCommentsService=new ClientCommentsServiceImpl3();
	public ClientCommentsServlet() {
		super();
	}

	public void destroy() {
		super.destroy(); // Just puts "destroy" string in log
		// Put your code here
	}

	public void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setContentType("text/html;charset=utf-8");
		response.setCharacterEncoding ("UTF-8");
		
		if ("support".equals(getServletName()))
		{
			request.getRequestDispatcher("/help.jsp").forward(request,response);     
		}else{
			String cnickname=request.getParameter("txtNickName");
			String cemail=request.getParameter("txtEmail");
			String canonymous=request.getParameter("chkAnonymous");
			String ccontent=request.getParameter("content");
			
			
			ClientComments clientComment=new ClientComments();
			if(canonymous!=null&&!"".equals(canonymous)){
				clientComment.setCnickname("匿名");
				clientComment.setCanonymous(1);
				clientComment.setCcontent(ccontent);
			}else{
				clientComment.setCnickname(cnickname);
				clientComment.setCemail(cemail);
				clientComment.setCanonymous(0);
				clientComment.setCcontent(ccontent);
			}
			clientComment=clientCommentsService.addClientComment(clientComment);
			String notice="感谢您的参与！";
			request.setAttribute("notice", notice);
			request.getRequestDispatcher("/jump_msg.jsp").forward(request,response);   
		}
		
	}

	public void init() throws ServletException {
		// Put your code here
	}

}
